<?php defined('SYSPATH') OR die('No direct access allowed.'); 
class Post_Model extends ORM{
	protected $has_many=array('comments');
        public function find_related_comments() {
            //$comments = ;
            //print_r ($comments);
            return ORM::factory('comment')->where('post_id',$this->id)->find_all();
        }
        public function get_articles(/*$year, $month = NULL, $day = NULL, $id = NULL*/) {
//            $key = 'date_format(ts,\'%Y\') = ';
//            $val = intval(Router::$arguments['year']);
//            echo $key.' '.$val;
            //$params = array( 'date_format(ts,\'%Y\') = ' => intval(Router::$arguments['year']));
            $params = 'date_format(ts,\'%Y\') = '.intval(Router::$arguments['year']);
            //(isset(Router::$arguments['month'])) AND $params['month'] = intval(Router::$arguments['month']);
            /*is_integer($day) AND $params['day'] = intval($day);
            is_integer($id) AND $params['id'] = intval($id);*/
            //$date = isset(Router::$arguments['year']) ? intval(Router::$arguments['year']) : date('Y');
            //$date .= 
            
            return ORM::factory('post')->where($params, null, -1)->find_all();
        }
}
